package com.roamer.audition.server.converter;

import com.roamer.audition.common.request.CompanyDTO;
import com.roamer.audition.common.request.CompanyPageQuery;
import com.roamer.audition.common.request.CompanyQuery;
import com.roamer.audition.common.response.CompanyVO;
import com.roamer.audition.server.entity.Company;
import com.roamer.audition.server.query.CompanyPageQuerySpecification;
import com.roamer.audition.server.query.CompanyQuerySpecification;
import org.mapstruct.*;

/**
 * 公司 数据转换接口
 *
 * @author roamer
 * @version V1.0
 * @date 2019/9/02 17:42
 */
@Mapper(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
        nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, componentModel = "spring")
public interface CompanyConverter {

    /**
     * DTO转换为Entity
     *
     * @param companyDTO DTO对象
     *
     * @return {@code Company}
     */
    @Mapping(target = "auditionRecordList", ignore = true)
    @Mapping(target = "version", ignore = true)
    @Mapping(target = "deleted", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    Company dtoToEntity(CompanyDTO companyDTO);

    /**
     * 转换为DTO
     *
     * @param company Entity对象
     *
     * @return {@code CompanyVO}
     */
    CompanyVO entityToVO(Company company);


    /**
     * Copy属性
     *
     * @param companyDTO 源DTO
     * @param company    目标Entity
     */
    @Mapping(target = "auditionRecordList", ignore = true)
    @Mapping(target = "version", ignore = true)
    @Mapping(target = "deleted", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    void copyNotNullPropertiesFromDTO(CompanyDTO companyDTO, @MappingTarget Company company);

    /**
     * 查询条件转换
     *
     * @param companyQuery 查询条件
     *
     * @return {@code CompanyQuerySpecification}
     */
    CompanyQuerySpecification queryToSpecification(CompanyQuery companyQuery);


    /**
     * 分页查询条件转换
     *
     * @param companyPageQuery 查询条件
     *
     * @return {@code CompanyPageQuerySpecification}
     */
    CompanyPageQuerySpecification pageQueryToSpecification(CompanyPageQuery companyPageQuery);
}
